proc DC_100012 { req } {
	global dbConnection
        set handle $dbConnection
	puts "in DC_100012:req=$req"
	list_to_array $req r_array
	set cert_type [string trim $r_array(Cert_Type) ]
	set cert_num  [string trim $r_array(Cert_Num)  ]
	set login_account [string trim $r_array(Login_Account) ]
	set login_passwd  [string trim $r_array(Login_Passwd)  ]
	set user_type     [string trim $r_array(User_Type)  ]
	set svc_num       [string trim $r_array(Svc_Num)  ]
	set user_passwd   [string trim $r_array(User_Passwd) ]

	set sql "select cust_id from lbs_customer where cert_num='$cert_num' and cert_type='$cert_type'";
	puts $sql
	set cust_id 0
	set result [::mysql::sel $handle $sql -list ]
	puts "result=$result,cust_id [lindex $result 0]"
	if {[lindex $result 0] == "" } {
		return  -code error "{{00000} {invalid cert_type and cert_num} }"

	} else {
		set cust_id [lindex $result 0]
		set account_id 0
		set sql "select account_id from lbs_account where cust_id=$cust_id"
		puts $sql
		set result [::mysql::sel $handle $sql -list ]
		puts "lndex--------- [lindex $result 0]"
		if { [lindex $result 0 ] != "" } {
		set account_id [lindex $result 0]
		puts "acccount_id=$account_id"
		} else {
			set sql "select max(ifnull(account_id,0))+1 from lbs_account "
			set result [::mysql::sel $handle $sql -list ]
			puts "lndex [lindex $result 0]"
			if {[lindex $result 0] == "" } {
				set account_id 1
				set sql "insert into lbs_account(account_id,cust_id,account_name,account_address,email) values($account_id,$cust_id,'','','')";
				puts $sql
			set result [::mysql::exec $handle $sql]
			} else {
				set account_id [lindex $result 0]
			}
			puts "acccount_id2=$account_id"
		}
		
		set sql "select max(ifnull(user_id,0))+1 from lbs_subscription"
		set result [::mysql::sel $handle $sql -list ]
		puts "result =$result"
		if {[lindex $result 0] == "" } {
			set user_id 1
			puts "user_id1=$user_id"
		} else {
			set user_id [lindex $result 0]
			puts "user_id2=$user_id"
		}
		set sql "insert into lbs_subscription(user_id,cust_id,account_id,user_type,svc_num,join_date,user_passwd) values($user_id,$cust_id,$account_id,'$user_type','$svc_num',now(),'$user_passwd')"
		puts $sql
		set result [::mysql::exec $handle $sql]
		return "{{00000} {{$user_id} {$account_id} {$cust_id}} }"
		
	}
	
}
